package com.softer.wxzj.controller;

import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.entity.BaseRegionInfo;
import com.softer.wxzj.entity.ResourceTree;
import com.softer.wxzj.entity.SysLoginInfo;
import com.softer.wxzj.entity.SysResource;
import com.softer.wxzj.service.HomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * HomeController class
 *
 * @author zcz
 * @date 2019/1/16
 */
@RestController
@RequestMapping("/home")
@Slf4j
public class HomeController {
    @Autowired
    HomeService homeService;
    @Value("${address}")
    private String address;

    @RequestMapping("/getMenu")
    @LogRecord(description = "获取菜单", operationUnit = LogOperationUnit.HOME, operationType = LogOperationType.SELECT)
    public List<SysResource> getMenu() {
        return homeService.getMenu(ShiroUserUtil.getUserName());
    }

    @RequestMapping("/getResourceTree")
    @LogRecord(description = "获取菜单", operationUnit = LogOperationUnit.HOME, operationType = LogOperationType.SELECT)
    public List<ResourceTree> getResourceTree() {
        return homeService.getResourceTree();
    }

    @RequestMapping("/getHomeTotal")
    @LogRecord(description = "首页统计", operationUnit = LogOperationUnit.HOME, operationType = LogOperationType.SELECT)
    public List<Map<String, String>> getHomeTotal() {
        return homeService.getHomeTotal();
    }

    @RequestMapping("/getHomeDetailTotal")
    @LogRecord(description = "首页统计", operationUnit = LogOperationUnit.HOME, operationType = LogOperationType.SELECT)
    public List<Map<String, String>> getHomeDetailTotal(String code) {
        return homeService.getHomeDetailTotal(code);
    }

    @RequestMapping("/getLoginInfo")
    @LogRecord(description = "获取上次登录记录", operationUnit = LogOperationUnit.HOME, operationType = LogOperationType.SELECT)
    public SysLoginInfo getLoginInfo(String operNo) {
        return homeService.getLoginInfo(operNo);
    }

    @RequestMapping("/getAllRegionByOperNo")
    @LogRecord(description = "主页--管辖区域信息", operationUnit = LogOperationUnit.HOME, operationType = LogOperationType.SELECT)
    public List<BaseRegionInfo> getAllRegionByOperNo(String operNo) {
        return homeService.getAllRegionByOperNo(operNo);
    }

    /**
     * 获取外网地址
     *
     * @return 外网地址
     */
    @PostMapping("/getAddress")
    public String getAddress() {
        return address;
    }
}
